﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace TheUglyGame
{
    class MainMenu : MenuBase
    {
        public MainMenu(string Headline, float MenuDrawPosX, float MenuDrawPosY, int MenuWidth, int MenuHeight, int ButtonCount) :
                   base(       Headline,       MenuDrawPosX,       MenuDrawPosY,     MenuWidth,     MenuHeight,     ButtonCount)
        {
            //evtl. Code
        }

        public MainMenu(string Headline, SpriteFont Font, float MenuDrawPosX, float MenuDrawPosY, int MenuWidth, int MenuHeight) :
                   base(       Headline,            Font,       MenuDrawPosX,       MenuDrawPosY,     MenuWidth,     MenuHeight)
        {
            //evtl. Code
        }

        public override void Load(ContentManager Content, SpriteBatch Spritebatch)
        {
            SetSpritebatch(Spritebatch);
            int x = (int)ButtonPos.X;
            int y = 0;
            int space = 0;

            //TexSetBackground laden

            for (int i = 0; i < ButtonCount; i++)
            {
                y = (int)ButtonPos.Y + space + (Const.MenuButtonHeight * i);
                Texture2D[] texset = new Texture2D[2];
                texset[0] = Content.Load<Texture2D>(Const.gfxMenuPath + "menu_btn" + (i+1) + "_a");
                texset[1] = Content.Load<Texture2D>(Const.gfxMenuPath + "menu_btn" + (i + 1) + "_b");

                MenuItem button = new MenuItem(x, y, Const.MenuButtonWidth, Const.MenuButtonHeight, texset);
                Buttons.Add(button);
                space += Const.MenuButtonSpace;
            }
            Buttons[0].Gamestate = Const.GameState.ClassMenu;
            Buttons[1].Gamestate = Const.GameState.Credits;
            Buttons[2].Gamestate = Const.GameState.Outro;
        }

        public override void Unload()
        {
            //Todo
        }

        public override void Draw()
        {
            //ToDo: Background zeichnen
            for (int i = 0; i < ButtonCount; i++)
                Spritebatch.Draw(Buttons[i].CurrentTex, Buttons[i].Rect, Color.White);
        }

        public override Const.GameState Update(MouseState Mousestate)
        {
            Const.GameState action = Const.GameState.MainMenu;
            Point MouseCoords = new Point(Mousestate.X, Mousestate.Y);

            //ToDo: Background updaten
            for (int i = 0; i < ButtonCount; i++)
            {
                if (Buttons[i].Rect.Contains(MouseCoords))
                {
                    Buttons[i].CurrentTex = Buttons[i].TexSet[1];
                    if (Mousestate.LeftButton == ButtonState.Pressed)
                        action = Buttons[i].Gamestate;
                }
                else
                    Buttons[i].CurrentTex = Buttons[i].TexSet[0];
            }
            return action;
        }

    }
}
